package com.wh.wisdomsite.xbox.core.threadpool;

import java.util.concurrent.FutureTask;


/**
 * 任务Task(实现Job接口, Comparable接口)
 * @Package com.wh.wisdomsite.xbox.core.threadpool
 * @author 谢泽鹏
 * @date 2014年10月8日 下午4:02:14
 * @Copyright 个人版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2014
 * @version V1.0
 */
public class JobFutureTask extends FutureTask<Object> implements Comparable<JobFutureTask>, Job {


    /**
     * job接口
     */
    private Job job;

    /**
     * 构造函数
     * @param job
     * @param result
     */
    public JobFutureTask(Job job, Object result) {
        super(job, result);
        this.job = job;
    }

    /**
     * 比较方法(重写)
     * @param jobFutureTask
     * @return
     */
    @Override
    public int compareTo(JobFutureTask jobFutureTask) {
        return (int) (job.getTimeout() - jobFutureTask.job.getTimeout());
    }

    /**
     * 获取Key
     * @return
     */
    @Override
    public String getKey() {
        return job.getKey();
    }


    /**
     * 获取Timeout
     * @return
     */
    @Override
    public long getTimeout() {
        return job.getTimeout();
    }

    /**
     * 获取doTimeout
     */
    @Override
    public void doTimeout() {
        job.doTimeout();
    }
}
